$sd = function (id, option) {
    var $d = document;
    var ie = $d.all ? true : false;
    function make(t, p, a, s, c) {
        var e = $d.createElement(t);
        if (a) { for (var i in a) e.setAttribute(i, a[i]); }
        if (s) { for (var i in s) e.style[i] = s[i]; }
        if (navigator && navigator.userAgent) { // make IE6, IE7 compatible
            var s = navigator.userAgent;
            if (s.indexOf('MSIE 6.0') > 0 || s.indexOf('MSIE 7.0') > 0)
                e = $d.createElement(e.outerHTML.replace('\r\n', ''));
        }
        if (p) p.appendChild(e);
        if (c) e.innerHTML = c;
        return e;
    }
    function addEvent(o, e, f) {
        if (o.addEventListener) o.addEventListener(e, f);
        else if (o.attachEvent) o.attachEvent('on' + e, f);
    }
    function setpx(o, s, v) { o.style[s] = v + 'px'; }
    function mx() {
        var w = window, b = $d.body, e = $d.documentElement, cw, ch, dw, dh;
        cw = (w.innerWidth) ? w.innerWidth : (e && e.clientWidth) ? e.clientWidth : b.offsetWidth;
        ch = (w.innerHeight) ? w.innerHeight : (e && e.clientHeight) ? e.clientHeight : b.offsetHeight;
        if (ie) { dw = e.scrollWidth; dh = e.scrollHeight > ch ? e.scrollHeight : ch; }
        else { dw = $d.width; dh = $d.height > ch ? $d.height: ch; }
        return [cw, ch, dw, dh];
    }
    var that = this;
    this.id = id; this.on = false;
    this.title = 'Smith Dialog'; this.width = 480; this.height = 220; this.shadow = 8; this.src = null;
    if (option) { // get option
        if (option.title) this.title = option.title;
        if (option.width) this.width = option.width;
        if (option.height) this.height = option.height;
        if (option.src) this.src = option.src;
    }
    if (!$sd.mask) $sd.mask = make('div', $d.body, { 'class': 'smithdialog_mask' });
    this.d = make('div', $d.body, { 'class': 'smithdialog' });
    this.s = make('div', this.d, { 'class': 'shadow' });
    this.w = make('div', this.d, { 'class': 'wrapper' });
    this.h = make('div', this.w, { 'class': 'head' });
    this.c = null;
    var x = make('a', this.h, { 'class': 'close', 'href': '#', 'title': 'Close', 'hidefocus': 'true' });
    var t = make('div', this.h, { 'class': 'title' }, null, this.title);
    if (this.src) {
        this.c = make('iframe', this.w, { 'frameborder': '0' });
    } else {
        var c = $d.getElementById(this.id);
        if (c) {
            this.c = c;
            c.parentNode.removeChild(c);
            this.w.appendChild(c);
        }
    }
    x.onclick = function () { that.close(); return false; }
    this.resize = function () {
        var ma = mx(), ww = this.width, wh = this.height, sw = this.shadow;
        setpx($sd.mask, 'width', ma[2]); setpx($sd.mask, 'height', ma[3]);
        setpx(this.w, 'width', ww); setpx(this.w, 'height', wh);
        setpx(this.w, 'left', sw); setpx(this.w, 'top', sw);
        if (this.c) { setpx(this.c, 'width', ww); setpx(this.c, 'height', wh - this.h.offsetHeight); }
        setpx(this.s, 'width', ww + sw * 2); setpx(this.s, 'height', wh + sw * 2);
        var dw = this.d.offsetWidth; var dh = this.d.offsetHeight;
        setpx(this.d, 'left', (ma[0] - dw) / 2); setpx(this.d, 'top', (ma[1] - dh) / 2);
    }
    this.close();
    addEvent(window, 'resize', function () { if (that.on) { that.resize(); } });
}
$sd.prototype.show = function () {
    if (!this.on) {
        $sd.mask.style.display = '';
        this.d.style.display = '';
        this.resize();
        if (this.src) this.c.src = this.src;
        this.on = true;
    }
    return false;
}
$sd.prototype.close = function () {
    this.d.style.display = 'none';
    $sd.mask.style.display = 'none';
    this.on = false;
    return false;
}
$sd.mask = null;
SmithDialog = $sd;